<template>
    <BasicModal
      v-bind="$attrs"
      @register="registerModal"
      show-footer
      width="30%"
      @ok="handleSubmit"
    >
      <template #title>
        新增
      </template>
      <template #footer>
        <a-button @click="closeModal">取消</a-button>
        <a-button
          type="primary"
          @click="handleSubmit(false)"
          :loading="btnLoading"
          >保存</a-button
        >
      </template>
      <BasicForm @register="registerForm">
      </BasicForm>  
    </BasicModal>
  </template>
  <script lang="ts" setup>
  import { ref } from 'vue';
  import { BasicModal, useModalInner } from '@/components/Modal';
  import { BasicForm, useForm } from '@/components/Form/index';
  import { useMessage } from '@/hooks/web/useMessage';
  import { useThrottleFn } from '@vueuse/core';
  import { defHttp } from '@/utils/http/axios';
  const emit = defineEmits(['success', 'register']);
  const btnLoading = ref(false);
  const { createMessage } = useMessage();
  const [
    registerForm,
    { resetFields, validate },
  ] = useForm({
    labelWidth: 100,
    schemas: [
   
      {
        field: 'id',
        component: 'Input',
        label: 'id',
        show: false,
      },
      {
        field: 'name',
        component: 'Input',
        label: '名称',
        required: true,
      },
    ],
    showActionButtonGroup: false,
    baseColProps: { span: 24 },
  });
 
  const [registerModal, { closeModal, changeLoading }] =
  useModalInner(async (data) => {
    });
  const handleSubmit = useThrottleFn(doSubmit, 1000);
  async function doSubmit(hasNext: boolean) {
    try {
      changeLoading(true);
      btnLoading.value = true;
      const values = await validate();
      const res = await defHttp.post({ url: '/chargeStandard/ChargeStandard/standardAdd', data: values.name });
      createMessage.success(res);
      emit('success');
      closeModal();
    } finally {
      btnLoading.value = false;
      changeLoading(false);
    }
  }
  </script>
  